package tech.aistar.corejava.day15;

/**
 * Created by 豆梦寒 on 2019/8/3.
 */
public class JoinDemo {
    public static void main(String[] args) {
        Mather m = new Mather();
        m.start();
    }

}
    class  Mather extends Thread{
        public void run(){
            System.out.println("老妈正在做饭");
            System.out.println("老妈发现酱油没了");
            System.out.println("老妈让孩子打酱油");
            //进入到阻塞状态 等孩子买完酱油之后才能继续做饭

            //创建son的线程
            Thread son = new Son();

            son.start();
            try {
                son.join();

                System.out.println("老妈可以继续做饭了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }
    }


    class Son extends Thread{
        public void run(){
            System.out.println("孩子去打酱油");

            for (int i = 5; i >=1; i--) {
                System.out.println("还有"+i+"分钟就回来了");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }


            }
            System.out.println("打完酱油回来了");
        }
    }



